package date0709am;

import java.sql.Connection;
import java.sql.SQLException;

import com.alibaba.druid.pool.DruidDataSource;
import com.mysql.cj.jdbc.MysqlDataSource;

import oracle.jdbc.pool.OracleDataSource;

/**
 * javax.sql.DataSource 接口的实例表示物理数据源。
 * 通过 DataSource 实例来获取数据库连接 (Connection) 是 DriverManager 首选替代方案。
 */
public class JdbcTest31 {

	public static void main(String[] args) throws SQLException {
		
		// MysqlDataSource 实现了 javax.sql.DataSource 接口
		MysqlDataSource ds = new MysqlDataSource() ;
		
		String param = "?serverTimezone=Asia/Shanghai&useSSL=false&useServerPrepStmts=true&cachePrepStmts=true" ;
		ds.setURL( "jdbc:mysql://localhost:3306/ecut" + param );
		ds.setUser( "ecuter" );
		ds.setPassword( "ecuter" );
		
		Connection conn = ds.getConnection();
		System.out.println( conn );
		conn.close();
		
		System.out.println( "- - - - - - - - - - - - - - - - - - - - -" );
		
		OracleDataSource ods = new OracleDataSource();
		
		ods.setURL( "jdbc:oracle:thin:@localhost:1521:ecut" );
		ods.setUser( "ecuter" );
		ods.setPassword( "ecuter" );
		
		conn = ods.getConnection();
		System.out.println( conn );
		conn.close();
		
		System.out.println( "- - - - - - - - - - - - - - - - - - - - -" );
		
		DruidDataSource dds = new DruidDataSource();
		
		dds.setDriverClassName( "oracle.jdbc.driver.OracleDriver" );
		dds.setUrl( "jdbc:oracle:thin:@localhost:1521:ecut" );
		dds.setUsername( "ecuter" );
		dds.setPassword( "ecuter" );
		
		conn = dds.getConnection();
		System.out.println( conn );
		conn.close();
		
		dds.close();
		
	}

}
